package com.kun.exception;

import com.kun.util.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 *
 * @author kun.li
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionAdvice {


    @ExceptionHandler({ServiceException.class})
    public ResponseResult serviceException(ServiceException serviceException) {
        log.error("serviceException: {}",serviceException.getMessage());
        return ResponseResult.error(serviceException.getMessage());
    }

    @ExceptionHandler({Exception.class})
    public ResponseResult exception(Exception exception) {
        log.error("exception: {}",exception.getMessage());
        return ResponseResult.error(exception.getMessage());
    }
}
